// 221024 liang pc后台路径 转 小程序路径
import { baseURL, } from './request'

let pcUrl2wxUrl = {
  // 首页
  './pages/home_page/home_page.html': {
    url: '',
    icon: '',
  },
  // 员工管理
  './pages/staff_management/staff_management.html?entity=all_employee_inf': {
    url: '',
    // icon: '../../image/workbench/yuangongguanli.png',
    icon: '../../image/workbench1/yuangongziliao.png',
  },
  // 用户管理
  './pages/user_management/user_management.html?entity=all_user': {
    url: '/DIYPages/user_management/user_management?entity=all_user',
    // icon: '../../image/workbench/yonghuguanli.png',
    icon: '../../image/workbench1/yonghuguanli.png',
  },
  // 公司架构
  './pages/corporate_architecture/corporate_architecture.html?entity=all_department': {
    url: '/DIYPages/company_structure/company_structure?entity=all_department',
    // icon: '../../image/workbench/gongsijiagou.png',
    icon: '../../image/workbench1/gongsijiagou.png',
  },
  // 分类数据
  './pages/sort_data/sort_data.html?entity=all_classify': {
    url: '',
    // icon: '../../image/workbench/feileishuju.png',
  },
  // 客户
  './pages/customer/customer.html?entity=customer': {
    url: '',
    // icon: '../../image/workbench/kehu.png',
    icon: '../../image/workbench1/kehuxinxi.png',
  },
  // 发布消息
  './pages/news_release/news_release.html?entity=training_materials': {
    url: '',
    // icon: '../../image/workbench/fabuxiaoxi.png',
  },
  // 报表设置
  './pages/financial_statement/report_design.html?entity=report_template': {
    url: '',
    // icon: '../../image/workbench/baobiaoshezhi.png',
  },
  // 新增凭证
  './pages/accounting/edit_voucher.html?entity=new_all_voucher&table_id=all_voucher&type=new': {
    url: '/accounting/accounting_voucher_add/accounting_voucher_add',
    // icon: '../../image/workbench/xinzengpingzheng.png',
    icon: '../../image/workbench1/xinzengpingzheng.png',
  },
  // 查凭证
  './pages/accounting/accounting_voucher.html?entity=all_voucher': {
    url: '/accounting/accounting_voucher/accounting_voucher?entity=all_voucher',
    // icon: '../../image/workbench/pingzheng.png',
    icon: '../../image/workbench1/chakanpingzheng2.png',
  },
  // 会计期管理
  './pages/accounting/accounting_period.html?entity=all_account_period': {
    url: '/accounting/accounting_period/accounting_period?entity=all_account_period',
    // icon: '../../image/workbench/kuaijiqiguanli.png',
    icon: '../../image/workbench1/kuaijiqiguanli.png',
  },
  // 会计科目表
  './pages/accounting/accounting_subject.html?entity=all_account': {
    url: '/accounting/accounting_subject/accounting_subject?entity=all_account',
    // icon: '../../image/workbench/kuaijikemubiao.png',
    icon: '../../image/workbench1/kuaijikemubiao.png',
  },
  // 科目汇总表
  './pages/accounting/summary_sheet_2.html?entity=all_account_summary_total': {
    url: '/accounting/account_summary/account_summary?entity=all_account_summary_total',
    // icon: '../../image/workbench/kemuhuizongbiao.png',
    icon: '../../image/workbench1/huizongbiao.png',
  },
  // 科目余额表
  './pages/accounting/summary_sheet.html?entity=all_account_summary': {
    url: '/accounting/account_balance/account_balance?entity=all_account_summary',
    // icon: '../../image/workbench/kemuyuebiao.png',
    icon: '../../image/workbench1/yuebiao.png',
  },
  // 科目明细账
  './pages/accounting/subject_detail.html?entity=all_voucher_statistics': {
    url: '/accounting/subject_detail/subject_detail?entity=all_voucher_statistics',
    // icon: '../../image/workbench/mingxi.png',
    icon: '../../image/workbench1/mingxizhang.png',
  },
  // 会计报表定义
  './pages/accounting/accounting_statement.html?entity=custom_account': {
    url: '',
   // icon: '../../image/workbench/baobiao.png',
  },
  // 利润表
  './pages/accounting/income_statement.html': {
    url: '/accounting/income_statement/income_statement',
    // icon: '../../image/workbench/lirunbiao.png',
    icon: '../../image/workbench1/lirunbiao.png',
  },
  // 资产负债表
  './pages/accounting/balance_sheet.html': {
    url: '/accounting/balance_sheet/balance_sheet',
    // icon: '../../image/workbench/zichanfuzhaibiao.png',
    icon: '../../image/workbench1/zichanfuzhaibiao.png',
  },
  // 辅助核算设置--无
  './pages/accounting/assist_account.html?entity=all_assist_account': {
    url: '',
   // icon: '../../image/workbench/fuzhuhesuanshezhi.png',
  },
  // 核算项目明细表--无
  './pages/accounting/assist_detail_account.html?entity=assist_account_details': {
    url: '',
    // icon: '../../image/workbench/mingxi.png',
    icon: '../../image/workbench1/hesuanxiangmumingxibiao.png',
  },
  // 核算项目余额表--无
  './pages/accounting/assist_balance_account.html?entity=query_assist_balance': {
    url: '',
    // icon: '../../image/workbench/hesuanxiangmuyuebiao.png',
    icon: '../../image/workbench1/hesuanxiangmuyuebiao.png',
  },
  // 出纳表
  './pages/cashier_table/teller_transaction.html?entity=all_cashier': {
    url: '/accounting/cashier_table/cashier_table?entity=all_cashier',
    // icon: '../../image/workbench/chunabiao.png',
    icon: '../../image/workbench1/chunabiao.png',
  },
  // 出纳科目表（资金账户表）
  './pages/accounting/cashier_subject.html?entity=all_cashier_account': {
    url: '/accounting/cashier_account/cashier_account?entity=all_cashier_account',
    // icon: '../../image/workbench/kuaijikemubiao.png',
    icon: '../../image/workbench1/zijinzhanghao.png',
  },
  // 出纳模块定义--无
  './pages/accounting/cashier_entity.html?entity=all_voucher_template': {
    url: '',
   // icon: '../../image/workbench/chunamokuaidingyi.png',
  },
  // 平台模板--无
  './pages/company_management/template_management.html?entity=platform_industry_template': {
    url: '',
   // icon: '../../image/workbench/pingtaimuban.png',
  },
  // 合同使用--无
  './pages/company_management/agent_customer.html?entity=sale_template_order_level3': {
    url: '',
   // icon: '../../image/workbench/hetongshiyong.png',
  },
  // 统计报表--无
  './pages/statistics_report/report_list.html': {
    url: '',
   // icon: '../../image/workbench/tongjibaobiao.png',
  },
  // 业务分析报表--无
  './pages/statistics_report/report_list_view.html?type=业务分析报表&entity=all_report_type_1': {
    url: '',
   // icon: '../../image/workbench/yewufenxibaobiao.png',
  },
  // 财务分析报表--无
  './pages/statistics_report/report_list_view.html?type=财务分析报表&entity=all_report_type_2': {
    url: '',
   // icon: '../../image/workbench/caiwufenxibaobiao.png',
  },
  // 库存参数设置
  './pages/inventory_management/stock_parameter.html?entity=stock_parameter': {
    url: '/stock/stock_parameter/stock_parameter?entity=stock_parameter',
    // icon: '../../image/workbench/kucuncanshushezhi.png',
    icon: '../../image/workbench1/canshushezhi.png',
  },

  // 商品定义
  './pages/inventory_management/product_list.html?entity=goods': {
    url: '/stock/goods/goods?entity=goods',
    // icon: '../../image/workbench/shangpindingyi.png',
    icon: '../../image/workbench1/shangpindingyi.png',
  },
  // 仓库定义
  './pages/inventory_management/warehouse_list.html?entity=Warehouse': {
    url: '/stock/warehouse/warehouse',
   icon: '../../image/workbench1/cangku.svg',
  },
  // 组装单列表
  './pages/inventory_management/assembly_list.html?entity=assembly_order': {
    url: '/stock/stock_custom_list/stock_custom_list?entity=assembly_order',
   icon: '../../image/workbench1/zuzhuangdan.svg',
  },
  // 组装单--无
  './pages/inventory_management/assembly.html?entity=assembly_order': {
    url: '',
   // icon: '../../image/workbench/zuzhuangdan.png',
  },
  // 拆卸单列表
  './pages/inventory_management/disassembly_list.html?entity=disassembly_order': {
    url: '/stock/stock_custom_list/stock_custom_list?entity=disassembly_order',
   icon: '../../image/workbench1/chaizhuangdan.svg',
  },
  // 拆卸单--无
  './pages/inventory_management/disassembly.html?entity=disassembly_order': {
    url: '',
   // icon: '../../image/workbench/chaixiedan.png',
  },
  // 调拨单列表
  './pages/inventory_management/transfer_list.html?entity=transfer_order': {
    url: '/stock/stock_custom_list/stock_custom_list?entity=transfer_order',
   icon: '../../image/workbench1/diaobodan.svg',
  },
  // 调拨单--无
  './pages/inventory_management/transfer.html?entity=transfer_order': {
    url: '',
   // icon: '../../image/workbench/diaobodan.png',
  },
  // bom表
  './pages/inventory_management/bom.html?entity=bom': {
    url: '/stock/bom/bom?entity=bom',
    // icon: '../../image/workbench/bombiao.png',
    icon: '../../image/workbench1/bombiao.png',
  },
  // 商品库存期初
  './pages/inventory_management/product_initial.html?entity=goods_opening_balance': {
    url: '/stock/stock_custom_list/stock_custom_list?entity=goods_opening_balance',
    // icon: '../../image/workbench/shangpinkucunqichu.png',
    icon: '../../image/workbench1/qichukucun.png',
  },
  // 库存模块定义--无
  './pages/inventory_management/stock_entity.html?entity=stock_entity': {
    url: '',
   // icon: '../../image/workbench/kucun.png',
  },
  // 商品库存余额表
  './pages/inventory_management/stock_balance.html': {
    url: '/stock/stock_balance/stock_balance',
    // icon: '../../image/workbench/hesuanxiangmuyuebiao.png',
    icon: '../../image/workbench1/kucunyuebiao.png',
  },
  // 商品收发明细表
  './pages/inventory_management/receive_send_detail.html': {
    url: '/stock/receive_send_detail/receive_send_detail',
    // icon: '../../image/workbench/mingxi2.png',
    icon: '../../image/workbench1/shoufamingxibiao.png',
  },
  // 商品收发汇总表
  './pages/inventory_management/receive_send_summary.html': {
    url: '/stock/receive_send_summary/receive_send_summary',
    // icon: '../../image/workbench/huizong.png',
    icon: '../../image/workbench1/shoufahuizongbiao.png',
  },
  // 跟进
  './pages/client_follow/client_follow.html?entity=all_followup': {
    url: '/DIYPages/client_follow/client_follow',
    // icon: '../../image/workbench/genjin.png',
    icon: '../../image/workbench1/genjin.png',
  },
  // 公海--无
  './pages/public_customer/public_customer.html?entity=customer': {
    url: '/pages/public_customer/public_customer?entity=customer',
   icon: '../../image/workbench1/gonghai.svg',
  },
}

let pcDiyUrl = './pages/general_entity/show_entity.html',
    wxDiyUrl = '/DIYPages/general_entity/general_entity'

const parseUrl = (rows) => {
  rows.forEach(row => {
    let child = row.children,
        menuURL = row.menuURL;

    //230118 yan 修改 删除菜单地址中&ident=后的字符串
    menuURL.indexOf('&ident=') >0 && (menuURL = menuURL.substring(0,menuURL.indexOf('&ident=')));

    if(menuURL) {
      let newUrl = pcUrl2wxUrl[menuURL]
      if(newUrl) newUrl = newUrl.url
      if(newUrl === undefined && menuURL.indexOf(pcDiyUrl) > -1) {
        newUrl = menuURL.replace(pcDiyUrl, wxDiyUrl)
        // 自定义模块才可以设置图标，固定页面使用固定图标
        if(row.miniprogram_icon_url === '') row.menuIcon = '../../image/workbench1/app_dflt.png'
        else row.menuIcon = baseURL + row.miniprogram_icon_url
      }
      row.wxMenuURL = newUrl
      // if(row.menuIcon === '#icon#') row.menuIcon = '../../image/workbench/app_dflt.png'
      if(row.miniprogram_icon_url === '') {
        let icon = ''
        if(pcUrl2wxUrl[menuURL]) icon = pcUrl2wxUrl[menuURL].icon
        if(!icon) icon = '../../image/workbench1/app_dflt.png'
        row.menuIcon = icon
      }
    }
    if(child && child.length) parseUrl(child)
  })
}

const hideBlankUrlMenu = (rows) => {
  let delIdx = []
  rows.forEach((row, i) => {
    let child = row.children
    if(row.menuURL && !row.wxMenuURL) delIdx.push(i)
    if(child && child.length) hideBlankUrlMenu(child)
  })
  delIdx.sort((a, b) => b - a)
  delIdx.forEach(i => rows.splice(i, 1))
}

wx.$parseUrl = (rows) => {
  parseUrl(rows)

  hideBlankUrlMenu(rows)
}
